<%@page contentType="text/html" %>
<%@page pageEncoding="UTF-8" %>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<%@taglib prefix="rich" uri="http://richfaces.org/rich" %>
<%@ taglib prefix="t" uri="http://myfaces.apache.org/tomahawk" %>


<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Goodwill - Отчет о недостающем товаре</title>
    <link rel="stylesheet" href="resources/css/main.css"/>
    <link rel="stylesheet" href="resources/css/stylesheet.css"/>
    <link rel="stylesheet" type="text/css" href="resources/css/jquery.countdown.css">
    <script type="text/javascript">
        function reloadPage() {
            window.location.reload();
        }
        //  Открыть страницу "Подробный отчет" в отдельном окне
        function openDRPage() {
            window.open("DetailedGoodAbsenceReport.jsf", "Подробный отчет", "width=800,height=600,resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no");
        }

        function openGAPage() {
            window.open("GoodTypeAbsenceReport.jsf", "Общая информация", "width=800,height=600,resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no");
        }
    </script>
</head>
<body>
<f:view>
    <jsp:include page="menu.jsp"/>
    <jsp:include page="status.jsp"/>

    <h:form id="absenceReportForm">
        <h:panelGrid columns="5" cellpadding="0" cellspacing="0">
            <h:outputText value="Дата: " styleClass="b"/>
            <h:outputText value=" c "/>
            <rich:calendar value="#{GoodAbsenceReportBean.beginDate}" locale="RU_ru"
                           datePattern="dd.MM.yyyy" style="width:80px;padding-left:4px;" id="calBegdate"/>
            <h:outputText value=" по "/>
            <rich:calendar value="#{GoodAbsenceReportBean.endDate}" locale="RU_ru"
                           datePattern="dd.MM.yyyy" style="width:80px;padding-left:4px;" id="calEnddate"/>
        </h:panelGrid>
        <h:outputText value="Фильтр: " styleClass="b"/>
        <h:panelGroup layout="block" styleClass="filter_subpanel">
            <h:outputText value="Группа товара"/>
            <h:selectOneMenu value="#{SessionBean.goodsFilter.goodTypeId}" styleClass="f_s" style="margin-left: 10px">
                <f:selectItems value="#{GoodTypesBean.goodTypesAsSelectItems}"/>
            </h:selectOneMenu>
        </h:panelGroup>
        <a4j:commandButton reRender="goodAbsenceReportTable" value="Применить" action="#{GoodsBean.applyFilter}"
                           style="margin-left: 10px"/>
        <a4j:commandButton id="AllRowsButton" value="#{GoodAbsenceReportBean.allRows?'Постраничный режим':'Все данные'}"
                           action="#{GoodAbsenceReportBean.showAllRows}" reRender="absenceReportForm"
                           style="margin-left: 10px"
                           status="none"/>
        <a4j:commandButton value="Общая информация" oncomplete="openGAPage()" style="margin-left: 10px"/>
        <rich:dataTable id="goodAbsenceReportTable"
                rows="#{GoodAbsenceReportBean.rowsCount}"
                value="#{GoodAbsenceReportBean.goods}"
                var="good"
                rowKeyVar="row"
                styleClass="full">
            <rich:column>
                <a4j:commandLink id="detailsLink"
                                 ajaxSingle="true"
                                 oncomplete="openDRPage()">
                    <h:graphicImage value="resources/img/edit.gif"/>
                        <f:setPropertyActionListener value="#{good}" target="#{GoodAbsenceReportBean.good}"/>
                </a4j:commandLink>
                <rich:toolTip for="detailsLink" value="Подробный отчет"/>
            </rich:column>
            <rich:column
                    sortBy="#{good.code}"
                    filterBy="#{good.code}"
                    filterEvent="onblur">
                <f:facet name="header">
                    <h:outputText value="Код"/>
                </f:facet>
                <h:outputText value="#{good.code}"/>
            </rich:column>
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="Наименование"/>
                </f:facet>
                <h:outputText value="#{good.name}"/>
            </rich:column>
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="Применимость"/>
                </f:facet>
                <h:outputText value="#{good.pr}"/>
            </rich:column>
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="На складе"/>
                </f:facet>
                <h:outputText value="#{good.count}"/>
            </rich:column>
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="В резерве"/>
                </f:facet>
                <h:outputText value="#{good.reservedCount}"/>
            </rich:column>
            <rich:column
                    sortBy="#{good.goodAbsenceCount}">
                <f:facet name="header">
                    <h:outputText value="Суммарная недосдача"/>
                </f:facet>
                <h:outputText value="#{good.goodAbsenceCount}"/>
            </rich:column>
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="Кол-во запросов"/>
                </f:facet>
                <h:outputText value="#{good.ordersCount}"/>
            </rich:column>
            <rich:column>
                <f:facet name="header">
                    <h:outputText value="Среднее значение"/>
                </f:facet>
                <h:outputText value="#{good.goodAbsenceCount/good.ordersCount}">
                    <f:convertNumber maxFractionDigits="2"/>
                </h:outputText>
            </rich:column>
            <f:facet name="footer">
                <rich:datascroller id="datascroller"/>
            </f:facet>
        </rich:dataTable>
    </h:form>
</f:view>
</body>